package com.huang.eduorder.service.impl;

import com.huang.eduorder.client.EduClient;
import com.huang.eduorder.client.OrderClient;
import com.huang.eduorder.entity.Order;
import com.huang.eduorder.mapper.OrderMapper;
import com.huang.eduorder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hunag.utils.OrderNoUtil;
import com.hunag.utils.orderVo.CourseWebVoOrder;
import com.hunag.utils.orderVo.UcenterOrder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-04-03
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private EduClient eduClient;
    @Autowired
    private OrderClient orderClient;

    @Override
    public String createOrder(String courseId, String id) {
        //远程调用获取用户信息
        CourseWebVoOrder courseInfoOrder = eduClient.getCourseInfoOrder(courseId);
        UcenterOrder ucenter = orderClient.getUcenter(id);

        Order order = new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfoOrder.getTitle());
        order.setCourseCover(courseInfoOrder.getCover());
        order.setTeacherName(courseInfoOrder.getTeacherName());
        order.setTotalFee(courseInfoOrder.getPrice());
        order.setMemberId(ucenter.getId());
        order.setMobile(ucenter.getMobile());
        order.setNickname(ucenter.getNickname());
        order.setStatus(0);
        order.setPayType(1);

        baseMapper.insert(order);

        return order.getOrderNo();
    }
}
